package com.xu.cloud.common.resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

/**
 * @author xuguan
 * @since 2023/7/13
 */
public class XuCloudMessageSource {
    private final MessageSource messageSource;
    private final Locale locale = LocaleContextHolder.getLocale();

    @Autowired
    public XuCloudMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    public String getMessage(String code, Object[] args) {
        return messageSource.getMessage(code, args, locale);
    }

    public String getMessage(String code, Object[] args, String defaultMsg) {
        return messageSource.getMessage(code, args, defaultMsg, locale);
    }
}
